﻿$.CallSelfAjaxMethod = function(method, data, callback) { var fullPathMethod = location.pathname + "/" + method; $.CallAjaxMethod(fullPathMethod, data, callback); }
$.CallAjaxMethod = function(method, data, callback) { $.ajax({ type: "POST", contentType: "application/json;utf-8", url: method, data: $.toJSON(data), success: callback }); };
$.CallSyncAjaxMethodWithoutMode = function(method, data, callback) { $.ajax({ type: "POST", contentType: "application/json;utf-8", async: false, url: method, data: $.toJSON(data), success: callback }); };

$.CallSyncAjaxMethod = function(method, data, callback) {

    var hfLang = $("input[id$='hfLang'][type='hidden']")[0];
    var lang = "处理中...";
    if (hfLang != null && hfLang.value != "zh-CN") {
        lang = "process...";
    }
    $(document.body).mask(lang);
    $.ajax({ type: "POST", contentType: "application/json;utf-8", async: false, url: method, data: $.toJSON(data), success: callback });
    setTimeout(function() { $(document.body).unmask(); }, 500);

};
$.fn.loadUserControl = function(control, showMask, params, isEnglish, callback, page) {
    var $dom = this;
    if (page == "" || page == null) {
        page = location.pathname; //.replace("/", "");
    }
    if (params == null) {
        params = "";
    }
    if (isEnglish == null) {
        isEnglish = false;
    }
    var param = { control: control, parameters: params, isEnglish: isEnglish };
    page += "/RenderUserControl"; //RenderUserControl是PageProxy中的方法，不要轻易修改
    if (showMask) {
        $.CallSyncAjaxMethod(page, param, function(result) {
            $dom.html(result.d);
        });
        if (callback) {
            callback();
        }
    }
    else {
        $.CallAjaxMethod(page, param, function(result) {
            $dom.html(result.d);
            if (callback) {
                callback();
            }
        });
    }



}

$.deleteContent = function(btn, id, callback) {
    $.CallSelfAjaxMethod("DeleteContent", { contentIDStr: id }, callback);
}


$.deleteEvent = function(btn, id, callback) {
    $.CallSelfAjaxMethod("DeleteEvent", { eventIDStr: id }, callback);
}

String.format = function() { if (arguments.length == 0) return null; var str = arguments[0]; for (var i = 1; i < arguments.length; i++) { var re = new RegExp('\\{' + (i - 1) + '\\}', 'gm'); str = str.replace(re, arguments[i]); } return str; };